package com.bank.frame;

import com.bank.utils.SystemConstants;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 用户登录后看到的面板
 */
public class UserPanel extends JPanel {
    private static JDesktopPane contentPanel = new JDesktopPane();// 主面板，比如表格之类的都在这里

    public UserPanel() {
        this.setBounds(0, 0, SystemConstants.FRAME_WIDTH, SystemConstants.FRAME_HEIGHT);
        contentPanel.setBounds(0, 20, SystemConstants.FRAME_WIDTH, SystemConstants.FRAME_HEIGHT - 50);
        this.add(contentPanel, BorderLayout.CENTER);// 中间
        JMenuBar menuBar = new JMenuBar();// 菜单栏的容器
        JMenu parentMenu = new JMenu("账户管理");// 一级菜单1
        JMenu systemMenu = new JMenu("系统管理");// 一级菜单2
        menuBar.add(parentMenu);// 将一级菜单放入容器
        menuBar.add(systemMenu);
        JMenuItem passwordMenu = new JMenuItem("修改登录密码");// 二级菜单1
        JMenuItem logoutMenu = new JMenuItem("退出登录");// 二级菜单2
        systemMenu.add(passwordMenu);
        systemMenu.add(logoutMenu);
        //  账户管理
        parentMenu.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                setContent(new UserAccountTablePanel());
            }
        });
        //  修改登录密码
        passwordMenu.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                setContent(new PasswordPanel());
            }
        });
        //  退出登录
        logoutMenu.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                contentPanel.removeAll();// 重新绘制窗口
                contentPanel.repaint();
                MainFrame.setContent(new LoginPanel());
            }
        });

        this.setLayout(new BorderLayout());
        menuBar.setBounds(0, 0, SystemConstants.FRAME_WIDTH, 50);// 菜单栏
        this.add(menuBar, BorderLayout.NORTH);// 上(北)
    }

    public static void setContent(JInternalFrame internalFrame) {
        internalFrame.setSize(SystemConstants.FRAME_WIDTH - 100, SystemConstants.FRAME_HEIGHT - 100);
        // 显示内部窗口
        internalFrame.setVisible(true);
        contentPanel.removeAll();// 重新绘制窗口
        contentPanel.repaint();
        contentPanel.add(internalFrame);
    }
}
